package org.dna;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class User {

    String fullname;
    org.dna.metronomo.persistence.User m_dbUser;

    public User(org.dna.metronomo.persistence.User dbUser) {
        this.m_dbUser = dbUser;
    }

    public org.dna.metronomo.persistence.User getUser() {
        return this.m_dbUser;
    }

    public String getPassword() {
        return m_dbUser.getPassword();
    }

    public String getFullname() {
        return this.m_dbUser.getName();
    }

    /**
     * Returns true if the user has one of roles passed into.
     *
     * @param roles, comma separated role names.
     * */
    public boolean hasRole(String[] roles) {
        Set<String> queryRoles = new HashSet<String>(Arrays.asList(roles));
        return queryRoles.contains(m_dbUser.getRole().toLowerCase());
    }

    public void setRole(String role) {
        m_dbUser.setRole(role.toUpperCase());
    }

    public String getRole() {
        return m_dbUser.getRole().toLowerCase();
    }
}
